package com.cybertron.ironhide.manage.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cybertron.ironhide.manage.common.Constants;
import com.cybertron.ironhide.manage.common.base.BaseAction;
import com.cybertron.ironhide.manage.util.FileUtil;

public class UploadAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1733173377948053390L;

	private static final Logger logger = LoggerFactory
			.getLogger(UploadAction.class);

	private Boolean resize = Boolean.TRUE;

	public void doUpload() throws IOException {
		String url = FileUtil.saveFile(filedata, filedataFileName, resize);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("url", url);
		ajaxJson(result);
	}

	public void doXheditorUpload() {
		logger.debug("xheditor upload start....");
		String err = "";
		String url = null;
		try {
			url = FileUtil.saveFile(filedata, filedataFileName);
		} catch (IOException e) {
			err = e.getMessage();
			e.printStackTrace();
		}

		Map<String, Object> result = new HashMap<String, Object>();
		result.put("url", url != null ? Constants.RESOURCE_ROOT_URL + url : "");
		result.put("err", err);
		ajaxJson(result);
		logger.debug("xheditor upload end....");
	}

	public Boolean getResize() {
		return resize;
	}

	public void setResize(Boolean resize) {
		this.resize = resize;
	}

}
